package task

import (
	"github.com/jinzhu/gorm"
	"kop/modules/chat/entity"
	"time"
)

// 定时删除聊天记录
func Task(dB *gorm.DB) {

	var ticker = time.NewTicker(time.Minute)
	for range ticker.C {

		var timestamp = time.Now().AddDate(0, 0, -7)
		dB.Where("created_at < ?", timestamp).Delete(entity.ServerChat{})
		dB.Where("created_at < ?", timestamp).Delete(entity.GuildChat{})
	}
}
